package org.datascooter.generator;

import java.util.HashMap;
import java.util.Map;

import org.datascooter.inface.IIdGenerator;

public class LongIncrementIdGenerator implements IIdGenerator<Long> {

	private final Long increment;
	private Long number = 0L;
	private Map<Object, Long> idMap = new HashMap<Object, Long>();

	public LongIncrementIdGenerator() {
		this(System.currentTimeMillis(), 1L);
	}

	public LongIncrementIdGenerator(Long seed, Long increment) {
		number = seed == null ? 0L : seed;
		this.increment = increment == null ? 1L : increment;
	}

	@Override
	public Long getId(Object value) {
		Long result = idMap.get(value);
		if (result == null) {
			number += increment;
			idMap.put(value, number);
			result = number;
		}
		return result;
	}
}
